#ifndef __VOICE_RECOGNIZER_API_H__
#define __VOICE_RECOGNIZER_API_H__

#include "Types.h"
#include "Defs.h"

#ifdef __cplusplus
extern "C" {
#endif

/// \defgroup 
/// 声波识别器接口
///	\n 调用流程图:
/// 
///    ============================================
///                   |                            
///            createVoiceRecognizer                      
///                   |
///                (addRef)
///                   | 
///                   |<-----|
///                   |            |
///             setFormat    |
///                   |            |
///                start          |
///                   |            |
///             getResult      |  
///                   |            |
///                stop          |
///                   |            |
///                   |------|
///                   | 
///                release                       
///                   |                            
///    ============================================
/// 
/// @{

///128个字节
typedef struct
{
    int frequency;      ///<声波分析器工作的采样率，默认44100HZ
    int soundMode;      ///<声波分析器工作的通道模式，默认单通道1
    int depth;          ///<声波分析器工作的位宽，默认16bit
    int type;           ///<音频数据格式，详见AudioEncType结构体，目前只支持PCM
    int Reserved[28];   ///<预留
}VoiceRecognizerFormat;

/// 音频识别缓冲结构体
typedef struct RecognizerBuf
{
	uchar	*buffer;				///< 数据缓冲指针
	int		len;					///< 数据长度
} RecognizerBuf;

///128个字节
typedef struct 
{
	RecognizerBuf   *rBuffer;	///< 数据缓冲数组，存储多个缓存地址，应用需依次读取
	int				length;		///< 数据缓冲有效长度
	int             rSize;		///< 数据缓冲数组大小，
	int Reserved[29];
}VoiceRecognizerResult;

///512个字节
typedef struct VoiceRecognizer
{
	/// 底层私有数据
	void *priv;

	/// 增加接口引用
	int (*addRef)(struct VoiceRecognizer *thiz);

	/// 释放接口
	int (*release)(struct VoiceRecognizer *thiz);

    /// 设置音频识别器的格式。
	///
	/// \param [in] thiz 本对象指针。
	/// \param [in] format 指向音频识别器格式结构VoiceRecognizerFormat的指针。
	/// \retval 0  设置成功
	/// \retval <0  设置失败
	int (*setFormat)(struct VoiceRecognizer *thiz, VoiceRecognizerFormat *format);

	/// 开始音频识别
	///
	/// \param [in] thiz 本对象指针
	/// \retval <0 开始失败
	/// \retval 0 开始成功
	int (*start)(struct VoiceRecognizer *thiz);

	/// 停止音频识别
	///
	/// \param [in] thiz 本对象指针
	/// \retval <0 停止失败
	/// \retval 0 停止成功
	int (*stop)(struct VoiceRecognizer *thiz);

    /// 获取音频识别结果
	///
	/// \param [in] thiz 本对象指针
	/// \param [in] pData 音频识别的数据
	/// \param [in] len 音频识别数据长度
	/// \param [out] pResult 音频识别结果
	/// \retval <0 识别失败
	/// \retval 0 识别成功
	int (*getPacket)(struct VoiceRecognizer *thiz, char *pData, int len, VoiceRecognizerResult *pResult);

	/// 释放数据
	/// \param [in] thiz 本对象指针
	int (*releasePacket)(struct VoiceRecognizer *thiz);

	/// 保留
	int reserved[120];
}VoiceRecognizer;

/// recognizer接口描述，128字节
typedef struct VoiceRecognizerDesc
{
	int reserved[32];			///< 保留
} VoiceRecognizerDesc;

/// 创建声波识别器接口。
///
/// \param [in] desc  flash接口描述结构RawFlashDesc指针
/// \param [out] flash flash接口指针的指针
/// \retval <0 创建失败
/// \retval 0 创建成功
int PAL_API createVoiceRecognizer(VoiceRecognizerDesc *desc, VoiceRecognizer **recognizer);

/// @} end of group

#ifdef __cplusplus
}
#endif

#endif //__VOICE_RECOGNIZER_API_H__
